package com.javafx.application;

import javafx.application.Application;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * 练习TreeTableView控件
 */

public class Main5 extends Application {
    public void start(Stage stage) throws Exception {
        stage.setTitle("树形表");
        Scene scene = new Scene(new Group(),200,400);
        Group sceneRoot = (Group)scene.getRoot();Group sceneRoot1 = (Group)scene.getRoot();

        //创建子节点
        final TreeItem childNode = new TreeItem("子节点1");
        final TreeItem childNode1 = new TreeItem("子节点2");
        final TreeItem childNode2 = new TreeItem("子节点3");

        //创建根节点
        final TreeItem root = new TreeItem("根节点");
        root.setExpanded(true);

        // 将子节点加入根节点中
        root.getChildren().addAll(childNode,childNode1,childNode2);

        //创建一个列
        TreeTableColumn<String,String> column = new TreeTableColumn<String, String>();
        column.setPrefWidth(150);

        //定义单元格内容
       /* column.setCellValueFactory((TreeTableColumn.CellDataFeatures<String, String> p) ->{
            new ReadOnlyStringWrapper(p.getValue().getValue());
        });*/

        column.setCellValueFactory((TreeTableColumn.CellDataFeatures<String, String> p) ->
                new ReadOnlyStringWrapper(p.getValue().getValue()));

        //创建一个TreetableView

        final TreeTableView treeTableView = new TreeTableView(root);
        treeTableView.getColumns().add(column);
        treeTableView.setPrefWidth(150);
        treeTableView.setShowRoot(true);
        sceneRoot.getChildren().add(treeTableView);

        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
